package com.example.appresult.common;

public class AppResult1<T>{
    private int code;
    private String message;

    private T data;


    //构造方法，两个参数的构造方法和三个阐述的构造方法

    public AppResult1(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public AppResult1(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    //封装常用的方法
    //成功
    public static AppResult1 success(){
        return new AppResult1(ResultCode.SUCESS.getCode(), ResultCode.SUCESS.getMessage());
    }

    public static <T>AppResult1<T> success(T data){
        return new AppResult1(ResultCode.SUCESS.getCode(), ResultCode.SUCESS.getMessage(),data);
    }

    public static <T>AppResult1<T>success(String message,T data){
        return new AppResult1(ResultCode.SUCESS.getCode(), message,data);
    }

    //封装失败的方法
    public static AppResult1 failed(){
        return new AppResult1(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }

    public static <T>AppResult1<T> failed(T data){
        return new AppResult1(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(),data);
    }

    public static <T>AppResult1<T>failed(String message,T data){
        return new AppResult1(ResultCode.FAILED.getCode(), message,data);
    }




    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
